#!/bin/sh

export CURRENT_APP_PATH="${LMD_APPS_DIR}/SillyTavern"
echo 'App Dir: '${CURRENT_APP_PATH}

export APP_INSTALL_NAME="sillytavern"

source "$LMD_BASE_INSTALL_SCRIPT_DIR/apps/sillytavern/env"
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/alias.sh"

if [ -d "$CURRENT_APP_PATH" ]; then
  echo "App Dir: "$CURRENT_APP_PATH
else
  echo "Error, App Dir dose not exist, please retry. "$CURRENT_APP_PATH
  exit 1
fi

cd "$CURRENT_APP_PATH"

node -v
export NODE_OPTIONS=--max-old-space-size=4096
npm run start

# PORT_PARAM=""
# if [ -n "$GRADIO_SERVER_PORT" ]; then
#   PORT_PARAM="--port $GRADIO_SERVER_PORT"
# fi
# cp "$LMD_BASE_INSTALL_SCRIPT_DIR/apps/$APP_INSTALL_NAME/lmd_run.js" "$CURRENT_APP_PATH"

# node server.js $PORT_PARAM
# node lmd_run.js $PORT_PARAM
